{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A (difficult) example (B.4)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:15.440147Z", "start_time": "2021-02-05T11:02:10.063803Z" }, "scrolled": false }, "outputs": [], "source": [ "from fractions import Fraction\n", "import sympy as sp\n", "from poisson_approval import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:15.448394Z", "start_time": "2021-02-05T11:02:15.442804Z" }, "scrolled": false }, "outputs": [], "source": [ "tau = TauVector({'a': Fraction(3, 20), 'b': Fraction(9, 20), 'ac': Fraction(1, 20), 'bc': Fraction(7, 20)},\n", " symbolic=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:16.464324Z", "start_time": "2021-02-05T11:02:15.450482Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{1}{5}$" ], "text/plain": [ "-1/5" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_ab.mu" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:16.532574Z", "start_time": "2021-02-05T11:02:16.468665Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{1}{5}$" ], "text/plain": [ "-1/5" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_bc.mu" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.465997Z", "start_time": "2021-02-05T11:02:16.535486Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{7}{10} + \\frac{\\sqrt{21}}{10}$" ], "text/plain": [ "-7/10 + sqrt(21)/10" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_ac.mu" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.478962Z", "start_time": "2021-02-05T11:02:17.469986Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{7}{10} + \\frac{\\sqrt{21}}{10}$" ], "text/plain": [ "-7/10 + sqrt(21)/10" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.trio.mu" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.498909Z", "start_time": "2021-02-05T11:02:17.481953Z" }, "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "-0.241742430504416" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float(tau.trio.mu)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\delta_{ab}(\\tau)$:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.543789Z", "start_time": "2021-02-05T11:02:17.503895Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{1}{8}$" ], "text/plain": [ "1/8" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.score_ab_in_duo_ab - tau.score_c_in_duo_ab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\delta_{bc}(\\tau)$:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.601633Z", "start_time": "2021-02-05T11:02:17.546781Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{1}{5}$" ], "text/plain": [ "1/5" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.score_bc_in_duo_bc - tau.score_a_in_duo_bc" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.612604Z", "start_time": "2021-02-05T11:02:17.605084Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2$" ], "text/plain": [ "2" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_ab.psi_ac" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.623575Z", "start_time": "2021-02-05T11:02:17.615596Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 1$" ], "text/plain": [ "1" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_bc.psi_a" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.633548Z", "start_time": "2021-02-05T11:02:17.625569Z" }, "scrolled": true }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{1}{3}$" ], "text/plain": [ "1/3" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_bc.psi_b" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.651501Z", "start_time": "2021-02-05T11:02:17.635543Z" }, "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "exp(- n/5 - log(n)/2 - log(8*pi/5)/2 + o(1))" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.duo_ab.asymptotic" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:17.669452Z", "start_time": "2021-02-05T11:02:17.655489Z" }, "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "exp(- n/5 - log(n)/2 - log(3*pi/5)/2 + o(1))" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.duo_bc.asymptotic" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:18.962992Z", "start_time": "2021-02-05T11:02:17.671447Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{27 \\sqrt{2}}{16 \\sqrt{3} + 27 \\sqrt{2}}$" ], "text/plain": [ "27*sqrt(2)/(16*sqrt(3) + 27*sqrt(2))" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "utility_threshold_program = tau.d_ranking_best_response['abc'].utility_threshold\n", "utility_threshold_program" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:18.977020Z", "start_time": "2021-02-05T11:02:18.964985Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{9 \\sqrt{3}}{8 \\sqrt{2} + 9 \\sqrt{3}}$" ], "text/plain": [ "9*sqrt(3)/(8*sqrt(2) + 9*sqrt(3))" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "utility_threshold_theoretical = 9 * sp.sqrt(3) / (9 * sp.sqrt(3) + 8 * sp.sqrt(2))\n", "utility_threshold_theoretical" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check that the value found by the program is actually the same as the theoretical value:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2021-02-05T11:02:19.489593Z", "start_time": "2021-02-05T11:02:18.978948Z" }, "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$" ], "text/plain": [ "0" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.simplify(utility_threshold_program - utility_threshold_theoretical)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }